﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using BrnMall.Manager.Domain.WebIM;
using BrnMall.Manager.Manager.WebIM;
using BrnMall.Services;
using Newtonsoft.Json;
using QIDong.WeApp.Util;
using WeiTap.Restful;

namespace QIDong.WeApp.Controllers
{
    /// <summary>
    /// 云通信
    /// </summary>
    public class WebIMController : WebApi
    {
        /// <summary>
        /// 获取腾讯云通信签名数据
        /// </summary>
        /// <param name="uid">用户编号</param>
        /// <returns></returns>
        public string FetchSign(int uid)
        {
            return WebIMUtil.GenSig(uid.ToString());
        }
        /// <summary>
        /// 导入IM用户信息
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public bool ImportWebIMUser(int uid)
        {
            var userInfo = Users.GetPartUserById(uid);
            Task.Factory.StartNew(() => WebIMUtil.ImportUser(userInfo), CancellationToken.None)
                   .ConfigureAwait(false);
            return true;
        }
        /// <summary>
        /// 自动加某人为好友，不需要审核
        /// </summary>
        /// <param name="uid">操作人UID</param>
        /// <param name="friendUid">好友UID</param>
        /// <returns></returns>
        public bool AddFriend(int uid, int friendUid)
        {
            WebIMUtil.AddFriend(uid,friendUid);
            return true;
        }
        

    }

    
}
